package org.sang.mapper.provider;

import org.apache.ibatis.jdbc.SQL;
import org.sang.bean.Member;
import org.springframework.util.StringUtils;

public class MemberProvider {

    private final String TABLE = "t_member_info";

    public String queryMemberParam(Member member) {
        SQL sql = new SQL().SELECT("*").FROM(TABLE);
        if (StringUtils.hasText(member.getName())) {
            sql.WHERE("name Like CONCAT('%',#{name},'%')");
        }
        if (StringUtils.hasText(member.getCardNo())) {
            sql.WHERE("card_no Like CONCAT('%',#{cardNo},'%')");
        }
        if (StringUtils.hasText(member.getStoreId())) {
            sql.WHERE("store_id = #{storeId}");
        }
        return sql.toString();
    }
}
